package com.cmpe.group6.storyroad.ListAdapters;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmpe.group6.storyroad.R;

/** List adapter for top rated stories list on main page.
 *
 */
public class TopRatedAdapter extends BaseAdapter {
	Context context;
	List<String> rowItems;
	List<String> ratings;
	List<String> tags;
	List<String> ids;

	/**
	 * @param context Current context.
	 * @param items Titles of the stories.
	 * @param ratings Ratings of the stories.
	 * @param tags Tags of the stories.
	 * @param ids Ids of the stories.
	 */
	public TopRatedAdapter(Context context, List<String> items,
			List<String> ratings, List<String> tags, List<String> ids) {
		this.context = context;
		this.rowItems = items;
		this.ratings = ratings;
		this.tags = tags;
		this.ids = ids;
	}

	/** View holder class for quicker generation.
	 *
	 */
	private class ViewHolder {

		TextView txtTitle;
		TextView txtDescRatings;
		TextView txtDescTags;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.rowItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.ids.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.list_item, null);
			holder = new ViewHolder();
			holder.txtDescRatings = (TextView) convertView
					.findViewById(R.id.desc_rating);
			holder.txtDescTags = (TextView) convertView
					.findViewById(R.id.desc_tags);
			holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		String title = this.rowItems.get(position);
		String rating = this.ratings.get(position);
		String tags = this.tags.get(position);

		holder.txtTitle.setText(title);
		holder.txtDescRatings.setText("Rating: " + rating);
		holder.txtDescTags.setText(tags);

		return convertView;
	}

}
